package com.qf.listener.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 * 通过代码方式创建 交换机和队列
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@Configuration
public class RabbitMqConfig {
    /*
    交换机和路由绑定
     */
    @Bean
    public Binding binding2(@Qualifier("queue2") Queue queue, FanoutExchange fanoutExchange){
        //绑定队列到交换机
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }

    @Bean
    public Binding binding1(@Qualifier("queue1") Queue queue, FanoutExchange fanoutExchange){
        //绑定队列到交换机
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }


    @Bean
    public FanoutExchange createExchange(){
        return new FanoutExchange("boot-fanout-exchange", false, false);
    }

    @Bean("queue1")
    public Queue  createQueue01() {
        //创建队列对象，并返回
        return new Queue("boot-queue1", true, false ,false , null);
    }


    @Bean("queue2")
    public Queue  createQueue02() {
        //创建队列对象，并返回
        return new Queue("boot-queue2", true, false ,false , null);
    }
}
